package com.xxr.mom.ci.charging.interworking.entity;

import com.xxr.mom.ci.common.base.BaseEntity;
import com.xxr.mom.ci.common.dto.EncryptionDecryptionDto;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @description: InterworkingConfig
 * @date: 2024/8/4 0:12
 * @author: natsuki_kining
 * @version: 1.0
 */
@Data
public class InterworkingConfig extends BaseEntity {

    /**
     * 1:互联互通
     * 2：监管
     */
    private Integer type;

    /**
     * 接口版本
     */
    private String version;

    /**
     * token名
     * 默认 Authorization
     */
    private String tokenHeadName;
    /**
     * 加密类型：默认对方
     * 1：用对方密钥
     * 2：用我方密钥
     */
    private Integer encryptType;
    /**
     * 解密类型：默认我方
     * 1：我方密钥
     * 2：对方密钥
     */
    private Integer decodeType;

    // 我方配置
    /**
     * 我方运营商标识
     */
    private String ownerId;
    /**
     * 我方运营商密钥
     */
    private String ownerSecret;
    /**
     * 我方运营商消息密钥
     */
    private String ownerDataSecret;
    /**
     * 我方运营商消息密钥初始化向量
     */
    private String ownerDataSecretIv;
    /**
     * 我方运营商签名密钥
     */
    private String ownerSigSecret;

    // 对方配置
    /**
     * 对方运营商标识
     */
    private String operatorId;
    /**
     * 对方运营商密钥
     */
    private String operatorSecret;
    /**
     * 对方运营商消息密钥
     */
    private String operatorDataSecret;
    /**
     * 对方运营商消息密钥初始化向量
     */
    private String operatorDataSecretIv;
    /**
     * 对方运营商签名密钥
     */
    private String operatorSigSecret;
    /**
     * 对方请求地址
     */
    private String operatorUrl;

    public String getTokenName() {
        if (StringUtils.isBlank(this.tokenHeadName)) {
            return "Authorization";
        }
        return tokenHeadName;
    }

    /**
     * 获取加密密钥
     * @return
     */
    public EncryptionDecryptionDto getEncrypt() {
        if (Objects.isNull(this.encryptType) || Objects.equals(1, this.encryptType)) {
            return new EncryptionDecryptionDto(this.operatorId, this.operatorSecret, this.operatorDataSecret, this.operatorDataSecretIv, this.operatorSigSecret);
        }
        return new EncryptionDecryptionDto(this.ownerId, this.ownerSecret, this.ownerDataSecret, this.ownerDataSecretIv, this.ownerSigSecret);
    }

    /**
     * 获取解密密钥
     * @return
     */
    public EncryptionDecryptionDto getDecode() {
        if (Objects.isNull(this.decodeType) || Objects.equals(1, this.decodeType)) {
            return new EncryptionDecryptionDto(this.ownerId, this.ownerSecret, this.ownerDataSecret, this.ownerDataSecretIv, this.ownerSigSecret);
        }
        return new EncryptionDecryptionDto(this.operatorId, this.operatorSecret, this.operatorDataSecret, this.operatorDataSecretIv, this.operatorSigSecret);
    }


}
